<template>
  <div class="dashboard-editor-container">
  <el-input
  placeholder="100"
  v-model="input"
  clearable>
    <el-button slot="append" icon="el-icon-search" @click="onSearch"></el-button>
</el-input>
    <div style="height: 20px"></div>

<!--    <panel-group @handleSetLineChartData="handleSetLineChartData" />-->

<!--    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">-->
<!--      <line-chart :chart-data="lineChartData" />-->
<!--    </el-row>-->

    <el-row :gutter="32">
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <raddar-chart />-->
<!--        </div>-->
<!--      </el-col>-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <pie-chart />-->
<!--        </div>-->
<!--      </el-col>-->
      <el-col :xs="24" :sm="24" :lg="18">
        <div class="chart-wrapper">
          <bar-chart :chart-data="userdata"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="6">
        <div>
          <el-table
    :data="rec"
    height="393"
    style="width: 100%"
    :row-class-name="tableRowClassName">
            <el-table-column
      type="index"
      width="40">
    </el-table-column>
    <el-table-column
      prop="itemId"
      label="推荐商品"
      >
    </el-table-column>
    <el-table-column
      prop="hot"
      label="推荐值"
      >
    </el-table-column>
  </el-table>
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <hot-pie-chart :chart-data="hotPie"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <buy-pie-chart :chart-data="buyPie"/>
        </div>
      </el-col>





    </el-row>
  </div>
</template>

<script>
import GithubCorner from '@/components/GithubCorner'
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import HotPieChart from "@/views/dashboard/admin/components/HotPieChart";
import BuyPieChart from "@/views/dashboard/admin/components/BuyPieChart";
import TransactionTable from './components/TransactionTable'
import axios from "axios";


const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    BuyPieChart,
    HotPieChart,
    GithubCorner,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      input: '100',
      // hotPie_keys:[],
      // hotPie_data:[],
      hotPie:{},
      buyPie:{},
      userdata:{},
      rec:[]

    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
        if (rowIndex % 2 === 1) {
          return 'warning-row';
        } else if (rowIndex % 2 === 0) {
          return 'success-row';
        }
        return '';
      },
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    onSearch(){
      // this.lineChartData.expectedData[0] = 1000
      // var _this = this
      //获取用户id，传给Api，进而查询数据库
      axios.post('http://localhost:8000/getUserType',{
        'userId':this.input
      }
          ).then(res=>{
              console.log(res.data)
              // this.hotPie_keys = res.data.hotPie_keys
              // this.hotPie_data = res.data.hotPie_data
              var test = {}
              test["hotPie_keys"] = res.data.hotPie_keys
              test["hotPie_data"] = res.data.hotPie_data
              this.hotPie = test
              var test2 = {}
              test2["buyPie_keys"] = res.data.buyPie_keys
              test2["buyPie_data"] = res.data.buyPie_data
              // this.buyPie_keys = res.data.buyPie_keys
              // this.buyPie_data = res.data.buyPie_data
              this.buyPie = test2
              // test = JSON.parse(JSON.stringify(res.data.hotPie))
              console.log(this.hotPie)
          })

      axios.post('http://localhost:8000/getUser',{
        'userId':this.input
      }
          ).then(res=>{
              var test = {}
              test["keys"] = res.data.keys
              test["values"] = res.data.values
              this.userdata = test
              console.log(this.userdata)
          })

      axios.post('http://localhost:8000/getrec',{
        'userId':this.input
      }
          ).then(res=>{
              var test = []
              test = res.data.rec
              this.rec = test
              console.log(this.rec)
          })
    }
  }
}
</script>
<style>
.el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}


</style>
